package com.gitee.feizns.quickstart.ding.talk.api.top.api.v2.user;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2UserGetRequest;
import com.dingtalk.api.response.OapiV2UserGetResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 调用本接口获取指定用户的详细信息（/topapi/v2/user/get）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/query-user-details">查询用户详情（/topapi/v2/user/get）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/query-user-details">服务端API 通讯录管理 用户管理 查询用户详情</a>
 * @author feizns
 * @since 2025/3/24
 */
public class Get {

    /**
     * 查询用户详情
     * @param accessToken 访问令牌
     * @param userid 用户编号
     * @return {@link OapiV2UserGetResponse.UserGetResponse }>
     */
    @SneakyThrows
    public static OapiV2UserGetResponse.UserGetResponse execute(String accessToken, String userid) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
        OapiV2UserGetRequest req = new OapiV2UserGetRequest();
        req.setUserid(userid);
        OapiV2UserGetResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getResult();
    }

}
